package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.CartService;
import cn.bytecollege.admin.service.CuisineService;
import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.Cuisine;
import cn.bytecollege.common.entity.Page;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "CuisineListController",value = "/admin/cuisineList")
public class CuisineListController extends HttpServlet {
    private CuisineService cuisineService=null;
    private CartService cartService = null;
    public CuisineListController() {
        cartService = new CartService();
        cuisineService=new CuisineService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String index=request.getParameter("index");
        int pageIndex=(index==null)?1:Integer.valueOf(index);
        String size=request.getParameter("size");
        int pageSize=(size==null)?10:Integer.parseInt(size);

        Page<Cuisine> page= cuisineService.findByPage(pageIndex,pageSize);
        request.setAttribute("page",page);
        request.getRequestDispatcher(Resource.PAGE_LOCATION+"/admin/cuisineList.jsp").forward(request,response);
    }
}
